#========================================
# This function sort takes an unsorted list of WRF output files as input,
# and return the sorted (by date-time) list as output.
#
# The format of the input file names should be standard WRF style like:
#                  yy mm dd hh  
#     wrfout_d01_2022-06-28_02:00:00
# Requirement:
#     1. 30 characters
#     2. 12-15: year
#     3. 17-18: month
#     4. 20-21: day
#     5. 23-24: hour
#     6. 25-27: minute
#     7. 29-30: second
#========================================

def wrf_sort_output(dfile_unsorted)
   # input file information:
   # dfile_unsorted: a list of WRF output files

   #Sort files according to date&time
    head_len = len(dfile_dir) + len(fil_prefx)
    years_unsort = []
    months_unsort = []
    days_unsort = []
    hours_unsort = []
    minutes_unsort = []
    seconds_unsort = []
    
    for dfname in dfile_names:
        years_unsort.append(dfname[head_len : head_len+4])
        months_unsort.append(dfname[head_len+5 : head_len+7])
        days_unsort.append(dfname[head_len+8 : head_len+10])
        hours_unsort.append(dfname[head_len+11 : head_len+13])
        minutes_unsort.append(dfname[head_len+14 : head_len+16])
        seconds_unsort.append(dfname[head_len+17 : head_len+19])
    #print(years_unsort)
    #print(months_unsort)
    #print(days_unsort)
    #print(hours_unsort)
    #print(minutes_unsort)
    #print(seconds_unsort)

    return dfile_sorted
